package com.bdqn.filters;

import javax.servlet.*;
import java.io.IOException;

public class EncodeFilter implements Filter {
    private String encode = "UTF-8";
    public void destroy() {
        encode = null;
    }

    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws ServletException, IOException {
        if (null == request.getCharacterEncoding()) {
            request.setCharacterEncoding(encode);
        }
        chain.doFilter(request, response);
    }

    public void init(FilterConfig filterConfig) {
        String encode = filterConfig.getInitParameter("encode");
        if (this.encode == null) {
            this.encode = encode;
        }
    }

}
